<?php
session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
if($_GET['act']=='del'){
$id=intval($_GET['id']);
$dbconn->noretquery("delete from ".DBQIAN."exchange where id=$id");
header("Location: ticketrecord.php?page=$_GET[page]");
};
$username = isset($_GET['username'])?$_GET['username']:'';
$time = isset($_GET['time'])?$_GET['time']:'';
if($_GET['act']=='status')
{
	if ($_GET['get']=='yes')
	{
		$where = '1 and '.DBQIAN.'exchange.type=3 and '.DBQIAN.'exchange.giftname!=\'no get praise\'';
	}
	else 
	{
		if ($_GET['status']==1)
		{
			$where = '1 and '.DBQIAN.'exchange.type=3 and '.DBQIAN.'exchange.status=1 and '.DBQIAN.'exchange.giftname!=\'no get praise\'';
		}
		else 
		{
			$where = '1 and '.DBQIAN.'exchange.type=3 and '.DBQIAN.'exchange.status<>1 and '.DBQIAN.'exchange.giftname!=\'no get praise\'';
		}
	}
}
else 
{
	$where = '1 and '.DBQIAN.'exchange.type=3';
	if($username)
	{
		$where .= ' and '.DBQIAN.'exchange.username=\''.$username.'\'';
	}
	if ($time)
	{
		$where .= ' and '.DBQIAN.'exchange.time>\''.$time.'\' and '.DBQIAN.'exchange.time<\''.substr($time,0,10).' 23:59:59\'';
	}
}
if($_GET['act']=='audit'){
$id=intval($_GET['id']);
$dbconn->noretquery("update ".DBQIAN."exchange set status=1 where id=$id");
header("Location: ticketrecord.php?page=$_GET[page]");
};
if ($_GET['act'] == 'trucate')
{
	$dbconn->noretquery("delete from ".DBQIAN."exchange where type=3");
	header("Location: ticketrecord.php");
}
echo '<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>欢迎登录后台管理系统</title>
<link href="css/base.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script language="JavaScript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-slide.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script>
$(document).ready(function(){
   $(function(){
   		$(\'#time\').datetimepicker();
      $(\'.rightinfo tbody tr:odd\').css("backgroundColor","#f5f8fa");
   });
});
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="index.php">首页</a></li>
    <li>红包领取记录</li>
  </ul>
</div>
<div class="rightinfo">
  <div class="tools"> 
    <ul class="toolbar">
    	 <li style="background:#FFF; text-indent:1em; border:0;margin-bottom:10px;">
      <form name="fsoso" method="get" action="">
        昵称 <input type="text" name="username" value="';echo $_GET['username'];;echo '" class="dfinput" style="width:200px" />
   时间 <input type="text" name="time" id="time" value="';echo $_GET['time'];;echo '" placeholder="格式：2015-12-01" class="dfinput" style="width:200px" />
      <input name="submit" class="btn" value="查询" type="submit" >
      </form></li><br>
      <!--<li><a href="excel.ticketrecord.php"><span><img src="images/ico03.png" /></span>导出</a></li> -->
       <li><a href="ticketrecord.php?act=status&status=1&get=yes"><span><img src="images/ico03.png" /></span>中奖</a></li> 
      <li><a href="ticketrecord.php?act=status&status=1"><span><img src="images/ico03.png" /></span>中奖已发放</a></li> 
      <li><a href="ticketrecord.php?act=status&status=0"><span><img src="images/ico03.png" /></span>中奖未发放</a></li> 
      <li><a onClick="if(confirm(\'您确认要清空吗？\')){location.href=\'?act=trucate\'}" href="#"><span><img src="images/t03.png" /></span>清空记录</a></li>

    </ul>
  </div><br/>
  <p style="height:15px;margin-bottom:10px;"></p>
  <table class="tablelist">
    <thead>
      <tr>
        <th width="10%">昵称</th>
        <th width="9%">性别</th>
        <th width="7%">积分</th>
        <th width="10%">礼品名称</th>
        <th width="6%">兑换数量</th>
        <th width="8%">兑换方式</th>
        <th width="13%">兑换时间</th>
        <th width="6%">是否发放</th>
        <th width="10%">操作</th>
      </tr>
    </thead>
    <tbody>
      ';
$page = ($_GET['page'] == ''||!isset($_GET['page'])) ?1:$_GET['page'];
$pagesize=12;
$num=$dbconn->countn(DBQIAN."exchange",$where);
$pagelist = new page($page,$pagesize,$num ,10,2,0);
$query=$dbconn->news_list(" select * from ".DBQIAN."exchange where ". $where ." order by id desc ",$page,$pagesize);
while($row=$dbconn->fetch($query)){
$urow=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."users where username='$row[username]'"));
$prow=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."post where id='$row[post_id]'"));
;echo '      <tr height="45">
        <td>';echo $row['username'];echo '</td>
        <td>';
if($urow['sex']=='') echo '未知';
if($urow['sex']=='男') echo '男';
if($urow['sex']=='女') echo '女';
;echo '</td>
		<td>';echo $row['credit'].'分';;echo '</td>
        <td>';echo $row['giftname'];;echo '</td>
        <td>';echo $row['qty'];;echo '</td>
        <td>';echo $prow['name'];;echo '</td>
         <td>';echo $row['time'];;echo '</td>
         <td>';
			if ($row['status']==1){
				echo "已发放";
			}
			else 
			{
				if($row['giftname'] == 'no get praise')
				{
					echo "无需发放";
				}
				else 
				{
					echo "未发放";	
				}
			}
		echo '</td>
        <td>
          <img src="images/t03.png" width="14"> 
          <a onClick="if(confirm(\'您确认要删除吗？\')){window.location.href=\'?act=del&id=';echo $row['id'];echo '&page=';echo $page;echo '\'}" href="#" class="tablelink">删除</a>
        	<img src="images/ice1.png" width="14">
	          ';
			  if($row['status']!=1){
			  	if($row['giftname'] == 'no get praise')
				{
					echo "发放";
				}
				else 
				{
	          		echo '<a onClick="if(confirm(\'您确认要发放礼品吗？\')){window.location.href=\'?act=audit&id=';echo $row['id'];echo '&page=';echo $page;echo '\'}" href="#" class="tablelink">发放</a>';
				}
			  }
	          else 
	          {
	          	
	          	echo '<span style="color:#ccc;">发放</span>';
	          }
        echo '</td>
      </tr>
          ';
//if($row['xtype']==2){echo "奖励红包";};echo '        </td>
//       
//      ';
}
;echo '    </tbody>
  </table>
</div>
<div style=" width:90%; padding:10px 0 10px 0; text-align:center">
  ';if($num!=0) echo $pagelist->showpages();else echo "<font color='#ff0000'>暂无数据</font>";;echo '</div>
</body>
</html>'
?>